﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System;

namespace Agility.Web.Models.DomainModel
{
    public partial class Assessment
    {
        void EpicAssessment_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "PotentialBusinessValue" || e.PropertyName == "Effort" || e.PropertyName == "StrategyAlignment")
            {
                if (this.PotentialBusinessValue.HasValue && this.EffortSize.HasValue && this.StrategyAlignment.HasValue)
                {
                    decimal effort;
                    if (this.EffortSize.Value == 0)
                        effort = 0.1M;
                    else
                        effort = this.EffortSize.Value;
                    this.RankingValue = (this.PotentialBusinessValue.Value / effort) * StrategyAlignment.Value;
                }
                else
                    this.RankingValue = null;
            }
        }

        public static List<AuthorizationAttribute> GetAuthorizationAttributes(string propertyName)
        {
            PropertyInfo propertyInfo = typeof(Epic).GetProperty(propertyName);
            object[] authorizationAttributes = propertyInfo.GetCustomAttributes(typeof(AuthorizationAttribute), false);
            return authorizationAttributes.Cast<AuthorizationAttribute>().ToList();
        }
    }
}